package cn.edu.xmut.chen.zhlg.zhlg.user.mapper;

import cn.edu.xmut.chen.zhlg.zhlg.user.entity.Resume;
import cn.edu.xmut.chen.zhlg.zhlg.user.result.ResumeResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ResumeMapper extends BaseMapper<Resume> {
    @Select("<script>" +
            "SELECT r.*, u.pic as aviator, u.phone " +
            "FROM tb_resume r " +
            "LEFT JOIN tb_user u ON r.user_id = u.id " +
            "WHERE 1=1 " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "   AND (r.name LIKE CONCAT('%', #{keyword}, '%') " +
            "   OR r.job LIKE CONCAT('%', #{keyword}, '%') " +
            "   OR r.description LIKE CONCAT('%', #{keyword}, '%')) " +
            "</if>" +
            "<if test='workExperience != null and workExperience != \"\"'>" +
            "   AND CASE " +
            "       WHEN #{workExperience} = '应届生' THEN r.work_experience = 0 " +
            "       WHEN #{workExperience} = '1-3年' THEN r.work_experience BETWEEN 1 AND 3 " +
            "       WHEN #{workExperience} = '3-5年' THEN r.work_experience BETWEEN 3 AND 5 " +
            "       WHEN #{workExperience} = '5-10年' THEN r.work_experience BETWEEN 5 AND 10 " +
            "       WHEN #{workExperience} = '10年以上' THEN r.work_experience > 10 " +
            "   END " +
            "</if>" +
            "<if test='degree != null and degree != \"\"'>" +
            "   AND r.degree = #{degree} " +
            "</if>" +
            "ORDER BY r.create_time DESC" +
            "</script>")
    Page<ResumeResult> pageSearch(Page<ResumeResult> page,
                                 @Param("keyword") String keyword,
                                 @Param("workExperience") String workExperience,
                                 @Param("degree") String degree);
} 